<template>
  <div class="app-container">
    <el-form :rules="formRules" ref="editForm" label-width="auto" :model="form" size="medium">
      <el-form-item label="当前学年" prop="currentYear">
        <year-select v-model="form.currentYear" str></year-select>
      </el-form-item>
      <el-form-item label="当前学期" prop="currentSemester">
        <semester-select v-model="form.currentSemester" str></semester-select>
      </el-form-item>
      <el-form-item label="本次选课开始时间" prop="selectionStartTime">
        <el-date-picker type="datetime" v-model="form.selectionStartTime" format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss" :clearable="false"></el-date-picker>
      </el-form-item>
      <el-form-item label="本次选课截止时间" prop="selectionEndTime">
        <el-date-picker type="datetime" v-model="form.selectionEndTime" format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss" :clearable="false"></el-date-picker>
      </el-form-item>
      <el-button type="primary" @click="onClickUpdate" :loading="loading">提交</el-button>
    </el-form>
  </div>
</template>

<script>
import {getConfigList, updateConfig, updateMoreByKey} from "@/api/config";
import ConfigValidator from "@/validator/ConfigValidator";
import YearSelect from "@/components/YearSelect";
import SemesterSelect from "@/components/SemesterSelect";

export default {
  components: {SemesterSelect, YearSelect},
  data() {
    return {
      queryListFun: getConfigList,
      updateFun: updateConfig,
      form: {
        currentYear: null,
        currentSemester: null,
        selectionStartTime: null,
        selectionEndTime: null
      },
      name: '配置',
      loading: false
    }
  },
  created() {
    this.queryListFun({}).then(res => {
      const data = {}
      for (let i of res.data) {
        data[i.key] = i.value
      }
      for (let i in data) {
        this.form[i] = data[i]
      }
    })
  },
  methods: {
    onClickUpdate() {
      this.loading = true
      updateMoreByKey(this.form).then(res => {
        this.$message({
          type: 'success',
          message: res.msg
        })
      }).finally(() => {
        this.loading = false
      })
    }
  }
}
</script>

<style scoped>

</style>
